﻿#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
using namespace std;
#include <string>

//C++11引入
class Base //final
{
public:
	void func5() { cout << "Base::func5()" << endl; }
protected:
	int a = 1;
private:
	//C++98的方法
	Base()
	{}
};

//class Derive : public Base
//{
//public:
//	void func4() { cout << "Derive::func4()" << endl; }
//};

//int main()
//{
//	//Derive d;
//	//无法调用父类的构造函数
//
//	return 0;
//}

#if 0
//前置声明
class Student;

class Person
{
public:
	//友元关系不会被继承
	friend void Display(const Person& p, const Student& s);
protected:
	string _name;//姓名
};

class Student : public Person
{
	friend void Display(const Person& p, const Student& s);
protected:
	int _stuNum;//学号
};

void Display(const Person& p, const Student& s)
{
	cout << p._name << endl;
	cout << s._stuNum << endl;
}

int main()
{
	Person p;
	Student s;
	Display(p, s);

	return 0;
}
#endif

#if 0
class Person
{
public:
	string _name;
	static int _count;
};
int Person::_count = 0;
class Student : public Person
{
protected:
	int _stuNum;
};

int main()
{
	Person p;
	Student s;

	cout << &p._name << endl;
	cout << &s._name << endl;

	cout << &p._count << endl;
	cout << &s._count << endl;

	cout << p._count << endl;
	cout << s._count << endl;

	Person::_count++;

	cout << Person::_count << endl;
	cout << Student::_count << endl;
	
	return 0;
}
#endif

#if 0
//菱形继承
class Person
{
public:
	Person(const char* name)
		:_name(name)
	{}
	string _name;//姓名
	/*int _tel;
	int _age;
	string _gender;
	string _address;*/
	//...
};

class Student : virtual public Person
{
public:
	Student(const char* name, int num = 0)
		:Person(name)
		,_num(num)
	{}
protected:
	int _num;//学号
};

class Teacher : virtual public Person
{
public:
	Teacher(const char* name, int id = 1)
		:Person(name)
		,_id(id)
	{}
protected:
	int _id;//职工编号
};

class Assistant : public Student, public Teacher
{
public:
	Assistant(const char* name1, const char* name2, const char* name3)
		:Student(name1)
		,Teacher(name2)
		,Person(name3)
	{}
protected:
	string _majorCourse;//主修课程
};

int main()
{
	//Assistant a;
	//a._name = "crayon";//访问不明确

	//a.Student::_name = "xxx";
	//a.Teacher::_name = "yyy";

	Assistant a("Mr.Yang", "Mr.Chen", "Mr.Led");

	return 0;
}
#endif

#if 0
class Base1 { public: int _b1; };
class Base2 { public: int _b2; };
class Derive : public Base2, public Base1 
{
public: 
	int _d = 3;
	int _e = 4;
};

int main()
{
	Derive d;
	Base1* p1 = &d;
	Base2* p2 = &d;
	Derive* p3 = &d;
	//p2 == p3 != p1

	return 0;
}
#endif 

// Tire(轮胎)和Car(车)更符合has-a的关系
class Tire 
{
protected:
	string _brand = "Michelin";//品牌
	size_t _size = 17;//尺寸
};
class Car 
{
protected:
	string _color = "颜色";//颜色
	string _num = "陕ABIT00";//⻋牌号
	Tire _t1;//轮胎
	Tire _t2;//轮胎
	Tire _t3;//轮胎
	Tire _t4;//轮胎
};

class BMW : public Car 
{
public:
	void Drive() { cout << "好开-操控" << endl; }
};

class Benz : public Car 
{
public:
	void Drive() { cout << "好坐-舒适" << endl; }
};


//stack和vector的关系，既符合is-a，也符合has-a
template<class T>
class stack : public vector<T>
{};
template<class T>
class stack
{
public:
	vector<T> _v;
};
int main()
{
	return 0;
}